<template>
	<view>
		<slot name="content"></slot>
		<!-- 加载更多组件 -->
		<load-more :visible="isLoadMore && showLoadmore" 
			:index="3" type="primary"></load-more>
		<!-- 没有更多了 -->
		<no-more :visible="loadAll && bindData.length>0 && showNoMore" 
			     :bgcolor="nmBgcolor"></no-more>
	</view> 
</template>

<script>
	/**
	 * plist组件 v1.0.2
	 * @author: Jie.
	 * @date: 2020-01-15
	 */
	import loadMore from"@/components/su-load/loadmore.vue";import noMore from"@/components/su-load/nomore.vue";export default{name:"suPlist",components:{loadMore:loadMore,noMore:noMore},props:{first:{type:Boolean,default:!1},config:{type:Object,default:()=>({})},params:{type:Object,default:()=>({})},isLoadMore:{type:Boolean,default:!0},showNoMore:{type:Boolean,default:!0},bindData:{type:Array,default:()=>[]},nmBgcolor:{type:String,default:"#f4f4f4"}},data:()=>({loadAll:!1,pageRow:{},showLoadmore:!1,dataKey:null,dataVersion:null}),created(){this.first&&this.refreshData()},methods:{refreshData(t){this.loadAll=!1,this.pageRow=this.config.pageRow,this.pageRow.page=1,this.showLoadmore=!1,this._getData("refresh",()=>{t&&t()})},loadMore(){this.loadAll||(this.pageRow.page+=1,this._getData("loadmore",()=>{}))},_getData(t,a){var e={...this.pageRow,...this.params};if(this.config.dataConfig&&this._queryParams(e),!this.config.action)return uni.core.toast("请配置action");uni.core.post(this.config.action,e,(e,o,s)=>{if(1==o){var i=[];try{i=JSON.parse(e.data.data)}catch(t){i=e}i.data&&(i.rows=i.data),i.rows.length>0?i.rows.length%this.pageRow.rows!=0&&this.pageRow.page>=1?(this.loadAll=!0,setTimeout(()=>{this.showLoadmore=!1},10)):setTimeout(()=>{this.showLoadmore=!0},10):this.pageRow.page>1?(this.loadAll=!0,setTimeout(()=>{this.showLoadmore=!1},10)):this.loadAll=!1,this._updateData(t,i),a&&a()}else this.pageRow.page>1?(this.loadAll=!0,setTimeout(()=>{this.showLoadmore=!1},10)):this.loadAll=!1,this._updateData(t,[]),a&&a()})},_updateData(t,a){let e=a.rows;if(e||(e=[]),"refresh"==t)this.$emit("update:bindData",e);else if("loadmore"==t){let t=this.bindData;t.push(...e),this.$emit("update:bindData",t)}this.$emit("receiveData",{type:t,data:a})},_queryParams(t){var a=this.config.dataConfig;this.dataKey=a.as_data_key,this.config.action=a.query.url,null==this.dataVersion?this.dataVersion=0:this.dataVersion>=0&&this.dataVersion++,t.Agilesoft_Data=!0,t.Agilesoft_DataKey=this.dataKey,t.Agilesoft_AskType="Agilesoft_IsAskRefresh",t.Agilesoft_Data_class="tbl://"+this.dataKey,t.Agilesoft_DataVersion=this.dataVersion},deleteData(t,a){var e=this.config.dataConfig;return e?t?(e.as_data_version=this.dataVersion,void uni.simpleData.utils(e,this).deleteData(t,(t,e,o)=>{a&&a(t,e,o)})):uni.core.toast("rowid is null"):uni.core.toast("data cfg is null")}}};
</script>

<style lang="scss">

</style>
